package com.example.service.impl;

import com.example.entity.CustomerVip;
import com.example.mapper.CustomerVipDao;
import com.example.service.CustomerVipService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (CustomerVip)表服务实现类
 *
 * @author makejava
 * @since 2024-05-18 18:53:59
 */
@Service("customerVipService")
public class CustomerVipServiceImpl implements CustomerVipService {
    @Resource
    private CustomerVipDao customerVipDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public CustomerVip queryById(Integer id) {
        return this.customerVipDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param customerVip 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<CustomerVip> queryByPage(CustomerVip customerVip, PageRequest pageRequest) {
        long total = this.customerVipDao.count(customerVip);
        return new PageImpl<>(this.customerVipDao.queryAllByLimit(customerVip, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param customerVip 实例对象
     * @return 实例对象
     */
    @Override
    public CustomerVip insert(CustomerVip customerVip) {
        this.customerVipDao.insert(customerVip);
        return customerVip;
    }

    /**
     * 修改数据
     *
     * @param customerVip 实例对象
     * @return 实例对象
     */
    @Override
    public CustomerVip update(CustomerVip customerVip) {
        this.customerVipDao.update(customerVip);
        return this.queryById(customerVip.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.customerVipDao.deleteById(id) > 0;
    }
}
